package com.warrior.controller;

import com.warrior.entity.TicketEntity;
import com.warrior.service.TicketService;
import com.warrior.util.CModelAndView;
import com.warrior.util.CommonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 票务controller
 * Created by Shawn on 2017/3/28.
 */
@Controller
@RequestMapping("/ticket")
public class TicketController {

    private static final Logger logger = LogManager.getLogger(TicketController.class.getName());

    @Autowired
    private TicketService ticketService;

    /**
     * 获取当前售票信息
     * @param page 当前页码
     * @param size 每页数据数
     * @param request request
     * @param response response
     * @return ModelAndView
     */
    @RequestMapping("/list")
    public ModelAndView listActivityByPage(String page, String size, HttpServletRequest request, HttpServletResponse response){
        if (logger.isDebugEnabled()) {
            logger.debug("listActivityByPage(String page={}, String size={}, HttpServletRequest request={}, HttpServletResponse response={}) - start", page, size, request, response); //$NON-NLS-1$
        }

        ModelAndView mv = new CModelAndView("/warrior/ticket/tickets_buy",request,response);
        //列出所有售票信息
        Page<TicketEntity> ticketEntities = this.ticketService.findAllTicketInPage(CommonUtils.String2Int(page), CommonUtils.String2Int(size), "desc");
        mv.addObject("ticketEntities",ticketEntities);

        if (logger.isDebugEnabled()) {
            logger.debug("listActivityByPage(String, String, HttpServletRequest, HttpServletResponse) - end"); //$NON-NLS-1$
        }
        return mv;
    }
}
